<template>
  <div class="choose-honor">
    <div class="table-data">
      <el-collapse-transition>
        <section class="main-search merge">
          <span class="svg-container">
            <svg-icon icon-class="search" />
          </span>
          <el-input v-model.trim="listQuery.honorName" placeholder="输入名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
          <section class="search-btn">
            <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
            <el-button type="primary" @click="handleReset">重置</el-button>
          </section>
        </section>
      </el-collapse-transition>
      <div class="classify-tab">
        <el-tabs v-model="activeTab" @tab-click="handleTabClick">
          <el-tab-pane
            v-for="item in dict.RYFL"
            :key="item.dictValue"
            :label="item.dictName"
            :name="item.dictValue"
          />
        </el-tabs>
      </div>
      <!--      honor-certificate  honor-achievement-->
      <v-table
        v-if="tag"
        :list="list"
        :tag="tag"
        :height="440"
        :selection="false"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :source-arr="['honorImg']"
      >
        <el-table-column
          fixed="right"
          label="操作"
          width="120"
          align="center"
        >
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleSelect(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </v-table>
      <div class="page">
        <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
      </div>
    </div>
  </div>
</template>

<script>
import { proofList, getDictByCode } from '../api'
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'

export default {
  name: 'ChooseCourse',
  components: { Pagination, VTable },
  props: {
  },
  data() {
    return {
      listLoading: false,
      definition: '1',
      getReward: '0',
      total: 0,
      tableData: [],
      listQuery: {
        page: 1,
        limit: 10,
        honorName: ''
      },
      multipleSelection: [],
      dict: {
        RYFL: []
      },
      activeTab: '',
      list: [],
      tag: '',
      view: '/API-DOCUMENT/document/file/download?id='

    }
  },
  computed: {},
  watch: {},
  created() {
    this.getDict('RYFL')
  },
  methods: {
    handleTabClick(tab, event) {
      this.listQuery.page = 1
      this.tag = this.activeTab === 'RYFL_ZS' ? 'honor-certificate' : 'honor-achievement'
      this.getList()
    },
    /**
     * 获取字典
     */
    getDict(code) {
      return new Promise((resolve, reject) => {
        getDictByCode(code).then(res => {
          this.dict[code] = (res.data.data && res.data.data.length > 0) ? res.data.data[0].list : []
          this.activeTab = this.dict[code][0].dictValue
          this.tag = this.activeTab === 'RYFL_ZS' ? 'honor-certificate' : 'honor-achievement'
          this.getList()
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },
    handleSelect(info) {
      this.$emit('select', { arr: info, chooseHonor: false })
    },
    handleReset() {
      this.listQuery.page = 1
      this.listQuery.name = ''
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        honorType: this.activeTab,
        honorName: this.listQuery.honorName
      }
      return new Promise((resolve, reject) => {
        proofList(query).then((res) => {
          console.log(res.data.data.rows)
          this.list = res.data.data.rows
          this.total = res.data.data.total
          this.listLoading = false
          console.log(this.total)
        })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    },

    filtercolumn(scope, item) {
      if (item === 'honorImg') {
        return `${this.view + scope.row['honorImg']}`
      }
      return scope.row[item]
    }
  }
}
</script>

<style type="text/css" lang="scss">
.choose-honor {
  height: 650px;
  display: flex;
  flex-direction: column;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }
  }
  .table-data {
    flex: 1;
  }
  .page {
    height: 50px;
  }
}
</style>
